﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace jDepot.Models
{
    public class jDepotRepository
    {
        private jDepotEntities entities = new jDepotEntities();

        public void AddProduct(Product p)
        {
            entities.Products.AddObject(p);
        }

        public Product[] SearchProduct(string productName, long productCategoryId)
        {
            return entities.Products.Where(p => ((string.IsNullOrEmpty(productName) || p.Name.StartsWith(productName)) && (productCategoryId == 0 || p.ProductCategoryId == productCategoryId))).ToArray();
        }

        public IQueryable<ProductCategory> GetAllProductCategories()
        {
            return entities.ProductCategories;
        }

        public void Save()
        {
            entities.SaveChanges();
        }
    }
}